<include file="public:header" />
<include file="public:left" />
<style>
    #goods_list{margin-left: 80px;float:left;width: 100%;}
    #goods_list li{width: 100px;border: 1px solid #999;float: left;margin: 2px;height: 180px;}
    #goods_list li img{width: 200px;margin-bottom: 5px;}
</style>

<form method="post" enctype="multipart/form-data">
    <input type="hidden" name="id" <if condition="isset($data['id'])">value="{$data.id}"</if>/>
    <section style="padding-bottom: 20px;">
        <h2><strong>推广详情</strong><a class="fr" href="{:url('Ad/index')}">返回推广列表</a></h2>

        <ul class="ulColumn2">
            <li>
                <span class="item_name" style="width:120px;">标题：</span>
                <input type="text" name="title" <if condition="isset($data['title'])">value="{$data.title}"</if>>
                <span>(标题15个字以内)</span>
            </li>
            <li>
                <span class="item_name" style="width:120px;">副标题：</span>
                <input type="text" name="subtitle" <if condition="isset($data['subtitle'])">value="{$data.subtitle}"</if>>
                <span>(副标题30个字以内)</span>
            </li>
            <li>
                <span class="item_name" style="width:120px;">图片：</span>
                <input type="file" name="image" >
                <if condition="isset($data['image'])"><img src="<?php echo IMG_PATH;?>{$data.image}" alt="" width="200px"></if>
            </li>
            <li>
                <span class="item_name" style="width:120px;">排序：</span>
                <input type="number" name="sort" <if condition="isset($data['sort'])">value="{$data.sort}"</if>>
            <li>
            <li>
                <span class="item_name" style="width:120px;">状态：</span>
                <input name="is_show" type="radio" value="1" <if condition="!isset($data['is_show']) || $data['is_show'] eq 1">checked</if>>显示
                <input name="is_show" type="radio" value="2" <if condition="isset($data['is_show']) && $data['is_show'] eq 2">checked</if>>隐藏
            </li>
            <li>
                <span class="item_name" style="width:120px;">类型：</span>
                <input name="type" type="radio" value="1" id="type1" <if condition="!isset($data['type']) || $data['type'] eq 1">checked</if>>商品
                <input name="type" type="radio" value="2" id="type2" <if condition="isset($data['type']) && $data['type'] eq 2">checked</if>>文章
            </li>
            <li <if condition='isset($data["type"]) && $data["type"] eq 2'>style="display: none"</if> class="goods">
                <span class="item_name" style="width:120px;">商品：</span>
                <input type="text" id="keyword" placeholder="商品名称">
                <span id="sub" style="border: 1px solid #999;padding: 5px;border-radius: 5px;">搜索</span>
            </li>
            <li <if condition='isset($data["type"]) && $data["type"] eq 2'>style="display: none"</if> class="goods">
                <span class="item_name" style="width:120px;"></span>
                <ul id="goods_list">
                    <if condition="isset($data['goods'])">
                    <li><input type="radio" name="goods_id" value="{$data.goods.id}" checked><img src="<?php echo IMG_PATH;?>{$data.goods.image}" style="width:100%;height:100%;" alt="">{$data.goods.name}
                    </li>
                    </if>
                </ul>
            </li>
            <li class="article" <if condition='!isset($data["type"]) || $data["type"] eq 1'>style="display: none"</if>>
                <span class="item_name" style="width:120px;">推广品牌：</span>
                <select name="brand_id">
                    <foreach name="$brand" item="b">
                        <option value="{$b.id}" <if condition="isset($data['brand_id']) && $data['brand_id'] eq $b['id']">selected</if>>{$b.name}</option>
                    </foreach>
                </select>
            </li>
            <li style="height:auto;<if condition='!isset($data["type"]) || $data["type"] eq 1'>display: none</if>" class="article">
                <span class="item_name" style="width:120px;">内容：</span>
                <script id="editor" name="content" type="text/plain" style="width:700px;height:300px;margin-left:125px; margin-top:-12px;"><if condition="isset($data['content'])">{$data.content|htmlspecialchars_decode}</if></script>
            </li>
            <li>
                <span class="item_name" style="width:120px;"></span>
                <input type="submit" class="link_btn" style="margin-top: 25px;" value="提交" />
            </li>
        </ul>
    </section>
</form>

</div>
</section>
<script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');


    function isFocus(e){
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }

    $('#type1').click(function () {
        $('.goods').show();
        $('.article').hide();
    });

    $('#type2').click(function () {
        $('.goods').hide();
        $('.article').show();
    });

    $('#sub').click(function () {
        var word = $('#keyword').val();
        $.ajax({
            url:"{:url('Ad/select_goods')}",
            type:"post",
            dataType:"json",
            data:{keyword:word},
            success:function (data) {
                console.log(data);
                if(data){
                    var goods = '';
                    for(var i=0;i < data.length;i++){
                        goods += '<li><input type="radio" name="goods_id" value="'+data[i].id+'" ';
                        if(i == 0){
                            goods += 'checked';
                        }
                        goods += '><img src="<?php echo IMG_PATH;?>'+data[i].image+'" alt="" style="width:100%;height:100%">'+data[i].name+'</li>';
                    }
                    $('#goods_list').html(goods);
                }
            }
        });
    });


</script>
</body>

</html>